home *** CD-ROM | disk | FTP | other *** search
/ Shareware Grab Bag / Shareware Grab Bag.iso / 007 / asm_subr.arc / FLOAT < prev    next >
Encoding:
Text File  |  1985-12-28  |  2.0 KB  |  79 lines

  1. ;-------------------------float routine begins--------------------------+
  2. ; from BLUEBOOK OF ASSEMBLY ROUTINES FOR IBM PC & XT.
  3. ;         page : 109
  4. ;
  5. ; NAME  FLOAT
  6. ;
  7. ; ROUTINE FOR Conversion from 16-Bit Integer to Floating Point
  8. ;
  9. ; FUNCTION: This routine converts an unsigned 16-bit binary number to a
  10. ; single precision binary floating point number.
  11. ;
  12. ; INPUT: Upon entry DX contains an unsigned 16-bit binary number
  13. ;
  14. ; OUTPUT: Upon exit SFPBUFF contains a single precision floating point
  15. ; number.  The single precision floating point number has a 24-bit binary
  16. ; mantissa, a sign bit, and an 8-bit exponent biased by 128.
  17. ;
  18. ; REGISTERS USED:  No registers are modified.  DX is used for input.
  19. ;
  20. ; SEGMENTS REFERENCED:  The data segment contains storage for the variable
  21. ; SFPBUFF and the message INTERNAL.
  22. ;
  23. ; ROUTINES CALLED:  STDMESSOUT, HEX16OUT, STDSPACE (All for debugging).
  24. ;
  25. ; SPECIAL NOTES: Equates are used to shorten address fields.
  26. ;
  27. ; ROUTINE TO CONVERT FROM INTERNAL INTEGER TO INTERNAL FLOATING POINT
  28. ;
  29. float    proc    far
  30. ;
  31. ; the number is in DX
  32. ;
  33.     push    dx        ; save registers
  34.     push    cx
  35.     push    ax
  36. ;
  37.     mov    ax,0        ; extend to 32 bits
  38.     cmp    dx,0        ; check if zero
  39.     jz    float4
  40. ;
  41. float1:
  42.     mox    cx,9800h    ; initialize exponent and sign
  43. ; shift left until normalized
  44. ;
  45. float2:
  46.     test    ax,0080h    ; done yet ?
  47.     jnz    float3        ; exit if true
  48.     sal    dx,1        ; shift all bits left if not
  49.     rcl    ax,1        ; carry on
  50.     dec    ch        ; decrement the exponent
  51.     jmp    float2
  52. ;
  53. float3:
  54. ;
  55. ; pack it in
  56.     and    ax,007Fh    ; just the mantissa
  57.     or    ax,cx        ; exponent and sign
  58. ;
  59. float4:
  60.     mov    sfpbuffw0,dx    ; put lower part into place
  61.     mov    sfpbuffw2,ax    ; put upper part into place
  62. ;
  63. ; show hex for debugging
  64.     lea    si,internal    ; point to message
  65.     call    stdmessout    ; send message
  66. ;
  67.     mov    dx,sfpbuffw2    ; upper word
  68.     call    hex16out    ; show it
  69. ;
  70.     call    stdspace    ; skip space
  71. ;
  72.     pop    ax        ; restore registers
  73.     pop    cx
  74.     pop    dx
  75.     ret            ; return
  76. ;
  77. float    endp
  78. ;-------------------------float routine ends---------------------------+
  79.